﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TrSubjectInfo.aspx.cs"  Inherits=" ZX.TR.Web.TrSubjectInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>题库管理</title>
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link type="text/css" rel="stylesheet" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function $(id) {
            return document.getElementById(id);
        }

        //由客户自己添加的行（G类工作项）
        function AddRow() {
            var tab = $("TabSubject");
            var hdf2 = $("HdfVid");

            var rl = tab.rows.length; //插入位置
            var indexid = parseInt(hdf2.value) + 1;
            //alert(indexid);
            //添加一行
            var newTr = tab.insertRow(rl);
            var tdr1 = $("TdFirst");
            //tdr1.rowSpan = indexid + 1; //合并
            //添加3列
            var newTd0 = newTr.insertCell(0);
            var newTd1 = newTr.insertCell(1);
            var newTd2 = newTr.insertCell(2);
            newTd2.colSpan = "2"
            //填充
            newTd0.innerHTML = indexid + '<input  type="hidden" ID="hd' + indexid + '" />';
            newTd1.innerHTML = '<textarea id="Ta' + indexid + '1" onkeypress="return MaxText(this,200);" onmouseover="return MaxText(this,200);"  class="style6" ></textarea>';
            newTd2.innerHTML = '<textarea id="Ta' + indexid + '2" onkeypress="return MaxText(this,200);" onmouseover="return MaxText(this,200);"  class="style6" ></textarea>';
            hdf2.value = parseInt(hdf2.value) + 1;
        }
        function DeleteRow() {
            var tab = $("TabSubject");
            var rl = tab.rows.length - 1; //插入位置

            if (tab.rows.length == 1) {
                alert("已到最后一行无法删除");
                return;
            }
            tab.deleteRow(rl);

            var hdf = $("HdfVid");
            hdf.value = parseInt(hdf.value) - 1;
            //alert(hdf.value);
        }

        function RefreshData() {
            if (parent.NeedRefreshPage != null) {
                if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
                    parent.NeedRefreshPage.LoadData();
                }
            }
        }

        function BeforeSave() {
            
            var hdf = $("HdfVid");
            var vx = ""; 
            var ddlTy = $("ddlType");
            if (ddlTy.value == "0661d140-0571-4dd3-9c5d-b5bc51ec16f5" || ddlTy.value == "1661d140-0571-4dd3-9c5d-b5bc51ec16f5") {
                for (var i = 1; i <= parseInt(hdf.value); i++) {
                    var hd = $("hd" + parseInt(i));
                    vx += hd.value + "|";
                    for (var j = 1; j <= 2; j++) {
                        var ta = $("Ta" + i + j);
                        vx += replaceAll(replaceAll(ta.value, "^", ""), "|", "") + "|";
                    }

                    vx += "^";
                }
            }
            var wwv = $("hdfWWValue");
            wwv.value = vx;
            
            
            var hdnName = $("txtSubjectName");
            var hdnCon = $("txtContent");
            var ddlRo = $("ddlRole");
            var hdnExp = $("txtExplain");
            var hdnRea = $("txtAnswer");
            var sidd = $("hdnSID");
            var hdf = $("HdfVid");
            var len = parseInt(hdf.value);  
            var back =  ZX.TR.Web.TrSubjectInfo.SavePlan(len,sidd.value, ddlTy.value, hdnName.value, ddlRo.value, hdnCon.value, hdnRea.value, hdnExp.value,vx).value;
            if (back == 1) {
                alert("保存成功！");
                parent.closeWin();
            }
            else
                alert("保存失败");
        }
        function CheckBeforeAdd() {

            var hdf = $("HdfVid");
            var len = parseInt(hdf.value);
            if (checkNull()) {
                var ddlTy = $("ddlType");
                if (ddlTy.value == "0661d140-0571-4dd3-9c5d-b5bc51ec16f5" || ddlTy.value == "1661d140-0571-4dd3-9c5d-b5bc51ec16f5") {
                    for (var i = 1; i <= len; i++) {
                        var ta1 = $("Ta" + i + "1");
                        var ta2 = $("Ta" + i + "2");
                        if (ta1.value == "") {
                            alert("请填写[标识]");
                            ta1.focus();
                            return false;
                        }
                        else if (ta2.value == "") {
                            alert("请填写[选项内容]");
                            ta2.focus();
                            return false;
                        }
                    }
                } return true;
            } else { return false; }
            
        }
        //保存前检查主表信息不能为空
        function checkNull() {
            var TaName = $("txtSubjectName");
            var TaContent = $("txtContent");
            var TaType = $("ddlType");
            var TaRole = $("ddlRole");
            if (TaName.value == "") {
                alert("题目名称不能为空!")
                TaName.focus();
                return false;
            } else if (TaType.value == "aa") {
                alert("请选择题目类型!")
                return false;
            } else if (TaRole.value == "bb") {
                alert("请选择题目角度!")
                return false;
            }else if (TaContent.value == "") {
                alert("题目内容不能为空!")
                TaContent.focus();
                return false;
            }
            return true;
        }
        //恢复控件及赋值
        function ReviewForm() {
            var HdfDiv = $("HdfVid");
            var len = parseInt(HdfDiv.value);
            HdfDiv.value = 1;
            if (len > 1) {
                for (var i = 1; i < len; i++) {
                    AddRow();
                }
            }

            //赋值
            var wv = $("hdfWWValue");
            if (wv.value != "") {
                var list = wv.value.split('^');
                for (var i = 0; i < list.length - 1; i++) {
                    var li = list[i].split('|');
                    var hd1 = $("hd" + parseInt(i + 1));
                    var ta1 = $("Ta" + parseInt(i + 1) + "1");
                    var ta2 = $("Ta" + parseInt(i + 1) + "2");

                    hd1.value = li[0];
                    ta1.value = li[1];
                    ta2.value = li[2];

                }
            }

        }

        function contains(string, substr, isIgnoreCase) {
            if (isIgnoreCase) {
                string = string.toLowerCase();
                substr = substr.toLowerCase();
            }
            var startChar = substr.substring(0, 1);
            var strLen = substr.length;
            for (var j = 0; j < string.length - strLen + 1; j++) {
                if (string.charAt(j) == startChar)  //如果匹配起始字符,开始查找
                {
                    if (string.substring(j, j + strLen) == substr)  //如果从j开始的字符与str匹配，那ok
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        //替换所有
        //s1原始字符串
        //s2子字符串
        //s3子字符串要替换成的值
        function replaceAll(s1, s2, s3) {
            var r = new RegExp(s2.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g, "\\$1"), "ig");
            return s1.replace(r, s3);
        }
        //只取一个URL参数：
        var queryString = function (key) {
            return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
        }
        //限制输入字数
        function MaxText(obj, max) {
            if (obj.value.length > max) {
                alert("最多可输入" + max + "个字");
                obj.value = obj.value.substr(0, max);
            }
        }

    </script>
    <style type="text/css">
        /* Table样式 */
        .tableContent
        {
            width: 100%;
            border-collapse: collapse;
        }
        .tableContent th
        {
            border: solid 1px #D4DBE2;
            font-weight: bold;
            background-color: #F2F8FF;
            white-space: nowrap;
            line-height: 28px;
            text-align: center;
        }
        .tableContent td
        {
            border: solid 1px #D4DBE2;
            background-color: #F2F8FF;
            line-height: 28px;
            text-align: center;
        }
        .style6
        {
            border-bottom: black 1px solid;
            border-top-style: none;
            border-right-style: none;
            border-left-style: none;
            background-color: white;
            overflow: hidden;
            height: 98%;
            width: 100%;
        }
        .style5
        {
            border-bottom: black 1px solid;
            border-top-style: none;
            border-right-style: none;
            border-left-style: none;
            background-color: white;
        }
        A
        {
            color: #1f376d;
        }
        A:hover
        {
            color: #bd0a01;
            text-decoration: underline;
        }
        A.lchot
        {
            color: #bd0a01;
        }
        A.lchot:visited
        {
            color: #bd0a01</style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="FormDiv">
        <asp:HiddenField ID="HdfVid" runat="server" Value="1" />
        <asp:HiddenField ID="hdfWWValue" runat="server" />   
        <asp:HiddenField runat="server" ID="ddlTy" />
        <asp:HiddenField runat="server" ID="ddlRo" />
        <asp:HiddenField runat="server" ID="hdnName" />
        <asp:HiddenField runat="server" ID="hdnCon" />
        <asp:HiddenField ID="hdnSID" runat="server" />
        <asp:HiddenField ID="hdnRea" runat="server" />
        <table class="tableContent" style="width: 100%; height: 100%;">
            <tr>
                <td>
                    题目名称：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtSubjectName" runat="server" CssClass="style6"></asp:TextBox>
                </td>
               
            </tr>
            <tr>
                 <td>
                    题目类型：
                </td>
                <td>
                    <asp:DropDownList ID="ddlType" AutoPostBack="true" onselectedindexchanged="ddlType_SelectedIndexChanged" runat="server" CssClass="style6" AppendDataBoundItems="true">
                        <asp:ListItem Value="aa">--选择题目类型--</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    题目角度：
                </td>
                <td>
                    <asp:DropDownList ID="ddlRole" runat="server" CssClass="style6" AppendDataBoundItems="true">
                        <asp:ListItem Value="bb">--选择题目角度--</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    题目内容：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtContent" TextMode="MultiLine" CssClass="style6" Rows="3" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    参考答案：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtAnswer" TextMode="MultiLine" CssClass="style6" Rows="3" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    说明：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtExplain" TextMode="MultiLine" CssClass="style6" Rows="3" runat="server"></asp:TextBox>
                </td>
            </tr>
        </table>
        <asp:Panel ID="pnlItems" runat="server" Visible="false">     
        <table id="TabSubject" class="tableContent" style="width: 100%; height: 100%;">
            <tr>
                <td colspan="4" style="text-align: left;">
                    <img src="../Images/Peixun/add.gif" title="添加选项" style="margin-left: 5px; cursor: pointer"
                        alt="添加行" onclick="return AddRow();" />
                    &nbsp; &nbsp; &nbsp; &nbsp;
                    <img src="../Images/Peixun/cancel.gif" title="删除选项" style="cursor: pointer" alt="删除行"
                        onclick="return DeleteRow();" />
                </td>
            </tr>
            <tr>
                <td>
                    序号
                </td>
                <td>
                    选项标识
                </td>
                <td colspan="2">
                    题目选项内容
                </td>
            </tr>
            <tr>
                <td id="TdFirst" style="width: 15%">
                    1<asp:HiddenField runat="server" ID="hd1" />
                </td>
                <td style="width: 20%;">
                    <textarea id="Ta11" 
                        class="style6"></textarea>
                </td>
                <td colspan="2">
                    <textarea id="Ta12" 
                        class="style6"></textarea>
                </td>
            </tr>
        </table>
        </asp:Panel>
    </div>
    </form>
</body>
<script type="text/javascript">
    function Save() {
        if (CheckBeforeAdd()) {
            BeforeSave();
            //关闭窗口
            var hdnDid = $("ddlType");
            parent.closeW(hdnDid.value);
          
        }
    }
</script>
</html>
